﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;

namespace Titan.WcfTest.Web
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service2
    {
         
        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        //[WebGet(RequestFormat = WebMessageFormat.Json)] 
        public Person DoWork(string name,int age)
        {
            Person p = new Person();
            p.Name = name;
            p.Age = age;
            return p;
        }

        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        //[WebGet(RequestFormat = WebMessageFormat.Json)] 
        public QueryExpression GetQueryParameter(string name, int age)
        {
            QueryExpression q = new QueryExpression();
            //q.Selects.Add("CustomerId");
            //q.Selects.Add("CustomerName");
            q.Wheres.Add("CustomerId", ConditionOperator.Equal, 55);
            q.Wheres.Add("CustomerName", ConditionOperator.Equal, "aa");
            q.Orders.Add("CustomerId", OrderType.Asc);
            q.Orders.Add("CustomerName", OrderType.Desc);

            //q.OrderBys2 = new List<IOrderExpression>();  
            //q.OrderBys2.Add(new OrderExpression( "CustomerId", OrderType.Asc));

            q.PageIndex = 2;
            q.PageSize = 3;
            q.ReturnMatchedCount = true; 
            return q;
        }

        [ServiceKnownType(typeof(DynamicEntity))]
        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        //[WebGet(RequestFormat = WebMessageFormat.Json)] 
        public IDynamicEntity GetDynamicEntity(string name, int age)
        {
            DynamicEntity obj = new DynamicEntity("Person");
            obj["Name"] = name;
            obj["Age"] = age;
            return obj;
        } 
    }
}
